package com.xbts.system.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.xbts.common.annotation.Excel;
import com.xbts.common.core.domain.BaseEntity;
import com.xbts.common.utils.StringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Update;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotEmpty;
import java.util.Date;
import java.util.Objects;

import static org.apache.poi.ss.usermodel.IndexedColors.SEA_GREEN;

/**
 * 积分申报对象 party_points_declaration
 *
 * @author xbts
 * @date 2023-06-12
 */
@Data
@ApiModel("积分申报对象")
@TableName("party_points_declaration")
public class PartyPointsDeclaration extends BaseEntity {

    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    @TableId
    private String id;

    /**
     * 活动编号
     */
    @Excel(name = "活动编号", headerBackgroundColor = SEA_GREEN)
    @NotEmpty(message = "活动编号不能为空", groups = Insert.class)
    private String activityCode;

    /**
     * 活动名称
     */
    @Excel(name = "活动名称", headerBackgroundColor = SEA_GREEN)
    @ApiModelProperty("活动名称")
    @NotEmpty(message = "活动名称不能为空", groups = Insert.class)
    private String activityName;

    /**
     * 活动类别，枚举：activity_classification
     */
    @Excel(name = "活动类别", dictType = "activity_classification", headerBackgroundColor = SEA_GREEN)
    @ApiModelProperty("活动类别，枚举：activity_classification")
    private String activityClassification;


    /**
     * 活动开始时间
     */
    @Excel(name = "活动开始时间", width = 20, dateFormat = "yyyy-MM-dd HH:mm:ss", headerBackgroundColor = SEA_GREEN)
    @ApiModelProperty("活动开始时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date activeCreateTime;

    /**
     * 活动开始时间
     */
    @Excel(name = "活动参加时间", width = 20, dateFormat = "yyyy-MM-dd HH:mm:ss", headerBackgroundColor = SEA_GREEN)
    @ApiModelProperty("活动参加时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date activeJoinTime;

    /**
     * 申报描述
     */
    @Excel(name = "申报描述", headerBackgroundColor = SEA_GREEN, width = 35)
    @ApiModelProperty("申报描述")
    @Length(min = 1, max = 100, message = "申报描述长度为1-100位")
    private String declarationDescribe;


    /**
     * 默认活动赠送积分
     */
    @Excel(name = "默认活动赠送积分", headerBackgroundColor = SEA_GREEN)
    @ApiModelProperty("默认活动赠送积分")
    private Double defaultRewardPoints;

    /**
     * 活动赠送积分
     */
    @Excel(name = "活动赠送积分", headerBackgroundColor = SEA_GREEN)
    @ApiModelProperty("活动赠送积分")
    private Double rewardPoints;

    /**
     * 文件名称：多个文件英文逗号分隔
     */
    @ApiModelProperty("文件名称：多个文件英文逗号分隔")
    @NotEmpty(message = "文件名称：多个文件英文逗号分隔不能为空", groups = Insert.class)
    private String fileNames;

    /**
     * 文件地址：多个文件英文逗号分隔
     */
    @ApiModelProperty("文件地址：多个文件英文逗号分隔")
    @NotEmpty(message = "文件地址：多个文件英文逗号分隔不能为空", groups = Insert.class)
    private String filePath;

    /**
     * 审核状态（0待审核 1通过 2驳回）
     */
    @Excel(name = "审核状态", readConverterExp = "0=待审核,1=通过,2=驳回", headerBackgroundColor = SEA_GREEN)
    private String status;

    /**
     * 驳回理由
     */
    @Excel(name = "驳回理由", headerBackgroundColor = SEA_GREEN)
    @ApiModelProperty("驳回理由")
    private String rejectReason;

    /**
     * 通过理由
     */
//    @Excel(name = "通过理由")
    @ApiModelProperty("通过理由")
    private String passReason;

    /**
     * 申报年份
     */
    @ApiModelProperty("申报年份")
    @NotEmpty(message = "申报年份不能为空", groups = Update.class)
    private String declarationYear;

    /**
     * 所属片区
     */
    private String belongToArea;

    /**
     * 所属片区名称
     */
    private String areaName;

    /**
     * 用户昵称
     */
    @TableField(exist = false)
    private String userNickName;

    public <T> QueryWrapper<T> queryWrapper() {
        QueryWrapper<T> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotEmpty(activityClassification), "activity_classification", activityClassification);
        queryWrapper.eq(StringUtils.isNotEmpty(belongToArea), "belong_to_area", belongToArea);
        if (StringUtils.isNotEmpty(areaName)) {
            queryWrapper.like("area_name", areaName.trim());
        }
        if (StringUtils.isNotEmpty(activityName)) {
            queryWrapper.like("activity_name", activityName.trim());
        }
//        queryWrapper.like(StringUtils.isNotEmpty(declarationDescribe), "declaration_describe", declarationDescribe);
//        queryWrapper.eq(!Objects.isNull(rewardPoints), "reward_points", rewardPoints);
//        queryWrapper.like(StringUtils.isNotEmpty(fileNames), "file_names", fileNames);
//        queryWrapper.like(StringUtils.isNotEmpty(filePath), "file_path", filePath);
        queryWrapper.eq(StringUtils.isNotEmpty(status), "status", status);
//        queryWrapper.like(StringUtils.isNotEmpty(rejectReason), "reject_reason", rejectReason);
//        queryWrapper.like(StringUtils.isNotEmpty(passReason), "pass_reason", passReason);
        if (StringUtils.isNotEmpty(declarationYear)) {
            queryWrapper.eq("status", 1);
            queryWrapper.eq("declaration_year", declarationYear);
        }
        return queryWrapper;
    }
}